<?php $secret_word="valhalla"; //change this
$enabled=false;

//admins: Edit this secret word which serves as a password.
//oneclick purgatory.
//Released under GNU GPL. Do what you want with it, just give credit where it's due.
//Anirudh Sanjeev
//http://anirudhsanjeev.org
//anirudh@anirudhsanjeev.org

if($_POST['sw']==$secret_word)
{
	setcookie('loggedin','yes',time()+3600);//log in
}
if($_GET['action']=='logout')
{
	setcookie('loggedin');//log out
}
?>
<?php 
if($enabled==false)
{
?>
<h1>OneClick Purgatory</h1>
Go to (your blog root)/wp-content/plugins/oneclick/purgatory.php and change the following things:<br>
change $secret_word to anything that you want.<br>
change $enabled=false to $enabled=true to prevent breaks<br>
<?php
}
else
{
if($_COOKIE['loggedin']!='yes')
{
?>
<h1>OneClick Purgatory</h1>

Enter the secret word, and if it's right, you can visit the purgatory. If you're the admin, change the secret word on the first line of the php file.
<br>
  <form action="<?php echo "\"",$_SERVER['PHP_SELF']; ?>" method="post">
  <input type="text" value="" name="sw" />
  <input type="submit" value="Enter" style="width:140px;" />
  </form><br>
  Instructions: After you enter the secret word, reload the page to see the purgatory. This bug also acts as a security measure :)
  <?

}
else
{
	//todo: The cookie shit
		
?>

<h1>OneClick Purgatory</h1>
<a href="<?php echo $_SERVER['PHP_SELF'],'?action=logout'; ?>">logout</a>
<h2>Instructions</h2>
<p>Use this page to delete misbehaving plugins/themes or make downloadable zip backups. Be careful while deleting files because it doesen't give you a gazillion "are you sure" warnings like most web2.0 places now.</p>

<?php
function recursive_remove_directory($directory, $empty=FALSE)
 {
     if(substr($directory,-1) == '/')
     {
         $directory = substr($directory,0,-1);
    }
    if(!file_exists($directory) || !is_dir($directory))
    {
         return FALSE;
     }elseif(!is_readable($directory))
     {
        return FALSE;
     }else{
         $handle = opendir($directory);
        while (FALSE !== ($item = readdir($handle)))
        {
             if($item != '.' && $item != '..')
           {
                 $path = $directory.'/'.$item;
                 if(is_dir($path)) 
                 {
                     recursive_remove_directory($path);
                }else{
                    unlink($path);
                }
             }
         }
         closedir($handle);
         if($empty == FALSE)
        {
          if(!rmdir($directory))
          {
               return FALSE;
            }
        }
    return TRUE;
     }
}
function backupthemes()
{
	require_once("pclzip.lib.php");
	$backup=new PclZip('../../octhemebckup.zip');
	$backup->create('../../themes');	
	backupplugins();
}function backupplugins()
{
	require_once("pclzip.lib.php");
	$backup=new PclZip('../../ocpluginbckup.zip');
	$backup->create('../');	
}
function humansize($size) {

    $kb = 1024;         // Kilobyte
    $mb = 1024 * $kb;   // Megabyte
    $gb = 1024 * $mb;   // Gigabyte
    $tb = 1024 * $gb;   // Terabyte

        if($size < $kb) return $size."B";
    else if($size < $mb) return round($size/$kb,0)."KB";
    else if($size < $gb) return round($size/$mb,0)."MB";
    else if($size < $tb) return round($size/$gb,0)."GB";
    else return round($size/$tb,2)."TB";
}
function handleBackups()
{
	if($_POST['backup']==='backupthemes')
	{
		backupthemes();
		?>right click on the link, and choose "save as" to download your backup: <a href="../../octhemebckup.zip">##LINK##</a><?php		
	}
	if($_POST['backup']==='backupplugins')
	{
		backupthemes();
		?>right click on the link, and choose "save as" to download your backup: <a href="../../ocpluginbckup.zip">##LINK##</a><?php		
	}
}
?>


<h2>Backup your plugin or theme directory</h2>
<p>
Click on one of the buttons to get a zipped up backup of your themes or plugins directories for your downloading pleasure.
<br>Clicking on one of the buttons gives you the download link.<br>
  <form action="<?php echo "\"",$_SERVER['PHP_SELF'],"?page=oneclick.php"; ?>" method="post">
  <input type="hidden" value="backupthemes" name="backup" />
  <input type="submit" value="BACKUP THEMES" style="width:140px;" />
  </form>
  <form action="<?php echo "\"",$_SERVER['PHP_SELF'],"?page=oneclick.php"; ?>" method="post">
  <input type="hidden" value="backupplugins" name="backup" />
  <input type="submit" value="BACKUP PLUGINS" style="width:140px;" />
  </form>
<?php handleBackups() ?>

</p>



<h2>Delete a Plugin Folder/File</h2>
<p>
Delete any plugin folder or file by clicking on the delete button. THE SYSTEM WILL NOT ASK YOU "ARE YOU SURE", so if you click, the directory will be destroyed. So be careful.<br />
<br />
<table class="widefat plugins">
<thead>
  <tr>
 <th>File/Folder Name</th>
<th style="text-align: center">Size</th>
<th style="text-align: center">Delete</th>
  </tr>
  </thead>
  <?php
$path= dirname($_SERVER['SCRIPT_FILENAME']).'/../';
$d = dir($path);
$icon = '';
$i=0;
while (false !== ($entry = $d->read())) {
$i++;
    if ( substr($entry, 0, 1)=='.' ) continue;

    // get size
    $size = filesize($path.'/'.$entry);
    $humansize = humansize($size);

    // find filename extension
    $dotpos = strrpos($entry, '.');
	$isafile=0;

	if($_POST["deleteid"]===$entry)//this file/folder is doomed
	{
	$i++;
	echo dirname($_SERVER['SCRIPT_FILENAME']).'/../'.$entry;
		if(is_file($path.'/'.$entry))
		{
			unlink(dirname($_SERVER['SCRIPT_FILENAME']).'/../'.$entry);
		}
		else
		{
			recursive_remove_directory(dirname($_SERVER['SCRIPT_FILENAME']).'/../'.$entry);

		}
	}
	else
	{
	?>
<tr>
    <td><?php echo $entry; backupthemes(); ?></td>
    <td>(<?php echo $humansize;  ?>)</td>
    <td><form action="<?php echo "\"",$_SERVER['PHP_SELF'],"?page=oneclick.php"; ?>" method="post">
    <input type="hidden" value="<?php echo $entry;  ?>" name="deleteid" />
<center><p class="submit"><input type="submit" value="DELETE!!!" style="width:140px;" /></p></center>     
    </form>
    </td>
  </tr>
	<?php
	}
}

$d->close();

?>
</table><br />
</p>
<h2>Delete a Theme Folder/File</h2>
<p>
Delete any theme folder or file by clicking on the delete button. THE SYSTEM WILL NOT ASK YOU "ARE YOU SURE", so if you click, the directory will be destroyed. So be careful.<br />

<table class="widefat plugins">
<thead>
  <tr>
 <th>File/Folder Name</th>
<th style="text-align: center">Size</th>
<th style="text-align: center">Delete</th>
  </tr>
  </thead>
<?php
$path= dirname($_SERVER['SCRIPT_FILENAME']).'/../../themes/';
$d = dir($path);
$icon = '';
$i=0;
while (false !== ($entry = $d->read())) {
$i++;
    if ( substr($entry, 0, 1)=='.' ) continue;

    // get size
    $size = filesize($path.'/'.$entry);
    $humansize = humansize($size);


    
    if($_POST["deleteid"]===$entry)//this file/folder is doomed
	{
	$i++;
		if(is_file($path.'/'.$entry))
		{
			unlink(dirname($_SERVER['SCRIPT_FILENAME']).'/../../themes/'.$entry);
		}
		else
		{
			recursive_remove_directory(dirname($_SERVER['SCRIPT_FILENAME']).'/../../themes/'.$entry);
		}
	}
	else
	{
	?>

<tr>
    <td><?php echo $entry;?></td>
    <td>(<?php echo $humansize;  ?>)</td>
    <td><form action="<?php echo "\"",$_SERVER['PHP_SELF'],"?page=oneclick.php"; ?>" method="post">
    <input type="hidden" value="<?php echo $entry; ?>" name="deleteid" />
    <center><p class="submit"><input type="submit" value="DELETE!!!" style="width:140px;" /></p></center>    
    </form>
    </td>
  </tr>
  
<?php	
	}
}
$d->close();

?><br />

</p>
</table>
<h2>About</h2>
The oneclick purgatory stemmed off from the 0.42 release of OneClick for wordpress, and is independent of wordpress database and code, so it can be used to easily tackle misbehaving plugins and themes. I'm too lazy to style this myself, but if you aren't and you do write some css for this painfully-web1.0 page, send it to me at anirudh@anirudhsanjeev.org, and i'll include it in the next release.
<?php
}}?>